package online.inote.dic.security.exception;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import online.inote.dic.common.utils.ResultFactory;
import online.inote.dic.common.utils.ResultFactory.ResultEnum;

/**
 * @description: 全局异常处理
 * @author XQF.Sui
 * @created 2019年4月29日 下午8:02:04
 * @version 1.0
 */
@ControllerAdvice
public class GloablExceptionHandler {

	@ResponseBody
	@ExceptionHandler(Exception.class)
	public Object handleException(Exception e) {
		
		if (StringUtils.isBlank(e.getMessage())) {
			return ResultFactory.fail("服务器异常");
		}
		
		if (StringUtils.contains(e.getMessage(), "重新登录")) {
			return ResultFactory.create(ResultEnum.TOKEN_EXPIRED, e.getMessage());
		}
		
		return ResultFactory.fail(e.getMessage());
	}
}